import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;

class Movie {
    private String name;
    private String director;
    private String actor;
    private String desc;
    private int duration; // 分钟
    private double score;

    public Movie(String name, String director, String actor, String desc, int duration, double score) {
        this.name = name; this.director = director; this.actor = actor;
        this.desc = desc; this.duration = duration; this.score = score;
    }

    public String getName() { return name; }
    @Override public String toString() {
        return name + "," + director + "," + actor + "," + desc + "," + duration + "," + score;
    }
    public static Movie fromString(String line) {
        String[] p = line.split(",");
        if (p.length != 6) return null;
        return new Movie(p[0], p[1], p[2], p[3], Integer.parseInt(p[4]), Double.parseDouble(p[5]));
    }
}

// ================= 电影管理 =================
class MovieManager {
    private List<Movie> movies = new ArrayList<>();
    private final String FILE_NAME = "movies.txt";

    public MovieManager() { loadMovies(); }

    private void loadMovies() {
        File f = new File(FILE_NAME);
        if (!f.exists()) return;
        try (BufferedReader br = new BufferedReader(new FileReader(f))) {
            String line;
            while ((line = br.readLine()) != null) {
                Movie m = Movie.fromString(line);
                if (m != null) movies.add(m);
            }
        } catch (IOException e) { e.printStackTrace(); }
    }

    public void saveMovies() {
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_NAME))) {
            for (Movie m : movies) {
                bw.write(m.toString());
                bw.newLine();
            }
        } catch (IOException e) { e.printStackTrace(); }
    }

    public void addMovie(Movie m) { movies.add(m); saveMovies(); }
    public void listMovies() { for (Movie m : movies) System.out.println(m); }
    public Movie findMovie(String name) {
        for (Movie m : movies) if (m.getName().equalsIgnoreCase(name)) return m;
        return null;
    }
}
